home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 22 / AACD 22.iso / CDTools / GoFetch! / arexx / Mike_King / AmFTPtoGoFetch.rexx
OS/2 REXX Batch file  |  2000-01-12  |  4KB  |  134 lines

  1. /*
  2.    This script reads in a batch file from amFTP and adds each
  3.    entry from it into GoFetch! Profiles so that GoFetch!
  4.    can be used to download the files.
  5.  
  6. Usage: 
  7.                 
  8.     You must have a profile in Amftp for the site you
  9.     want to download all the files from.
  10.  
  11.     Logon to that site from amftp and save a batch list
  12.     of all the files you want to download.
  13.  
  14.     Name the Batch list the EXACT name as the Profile used
  15.     in amftp's default batch directory.
  16.  
  17.     Then Run this script using the batch list filename as the
  18.     argument.
  19.  
  20.         Example:  
  21.  
  22.         Save a batch of files from aminet into a file name AMINET
  23.             in amftp's batches/ directory.  Then run the script
  24.         Batch->GoFetch AMINET
  25.  
  26. Program:
  27.  
  28.     The program Uses the argument to load the file from amftp's batch directory.  It
  29.     always uses the batch directory.  Then it starts reading files from
  30.     batch list.  It finds the profile in amftp that matches the
  31.     filename to get all the conenction information from.
  32.  
  33.     Then it creates a directory structure for the files in your download
  34.     location that matches the deepest directory name from the site.
  35.     This keeps everything organised.
  36.  
  37.     Then it adds all the files as profiles into GoFetch!
  38.  
  39.  
  40. NOTE:   
  41.     You will need to alter the paths in this file if you want it to 
  42.     automatically startup GoFetch! and amftp when needed.
  43.  
  44.  
  45. That's it.
  46.  
  47. Created Entirely by: 
  48.  
  49.     Michael King
  50.     3D graphics modeller and animator
  51.     mike@ethereal3d.com
  52.     http://www.ethereal3d.com
  53.  
  54. */
  55.  
  56.  
  57. OPTIONS RESULTS
  58. parse arg batchlist
  59.  
  60.  
  61. IF ~SHOW('P', 'GOFETCH') then
  62. DO
  63.   address COMMAND "wbrun work:com/net/GoFetch!"
  64.   address COMMAND "rexx:rexxc/waitforport GOFETCH"
  65. END
  66.  
  67.  
  68. IF ~SHOW('P', 'AMFTP.1') then
  69. DO
  70.   address COMMAND "wbrun work:com/net/amftp/amftp"
  71.   address COMMAND "rexx:rexxc/waitforport AMFTP.1"
  72. END
  73.  
  74. /* Open rexxsupport.library, and AMFTP Rexx-Port */
  75. ADDLIB("rexxsupport.library",0,-30,0)
  76. RXLIB "AMFTP.1"
  77. ADDRESS 'AMFTP.1'
  78.  
  79. /* Create MessagePort */
  80. CALL OPENPORT("AMFTP-RESULT.1")
  81.  
  82. /* Read the batchlist file */
  83. OPEN('Batchfile', '/batches/'batchlist, 'R')
  84.  
  85. /* Find the matching number of the profile in amftp*/
  86. profile_number = 0
  87. DO while (COMPARE(MYPRF.LABEL,batchlist)>0) 
  88.  GETPROFILE profile_number "MYPRF"
  89.  profile_number = profile_number + 1
  90. END
  91. profile_number = profile_number - 1
  92.  
  93. DO WHILE( EOF('Batchfile') == 0 )
  94.     /* Determine remote directory */
  95.   FullFileName = READLN('Batchfile')
  96.  
  97.     if words(FullFIleName) = 0 Then break
  98.  
  99.   charstored = LASTPOS('/', FullFileName)
  100.   OPEN('TempFILE', 'TempFILE', 'W')
  101.   WRITECH('TempFILE', FullFileName)
  102.   CLOSE('TempFILE')
  103.   OPEN('TempFILE', TempFILE)
  104.   directory = READCH('TempFILE', LASTPOS('/', FullFileName))
  105.  
  106.   /* Make a directory to match the file list */
  107.   OPEN('TempFILE2', 'TempFILE2', 'W')
  108.   WRITECH('TempFILE2', FullFileName)
  109.   CLOSE('TempFILE2')
  110.   OPEN('TempFILE2', TempFILE2)
  111.   rootdir = READCH('TempFILE2', (LASTPOS('/', directory) -1) )
  112.   CLOSE('TempFILE2')
  113.  
  114.   temp = LENGTH(rootdir) - LASTPOS('/', rootdir)
  115.   mkdir = right(rootdir, temp )
  116.     say "Found this: "MYPRF.LOCALDIR"/"mkdir
  117.   if ~EXISTS(MYPRF.LOCALDIR'/'mkdir) THEN
  118.     address command 'makedir >NIL: <NIL: 'MYPRF.LOCALDIR'/'mkdir
  119.   endif
  120.  
  121.   /* Determine the file */
  122.   DLfilename = READCH('TempFILE', (LASTPOS('|', FullFileName) - LASTPOS('/', FUllFileName) - 1) )
  123.   CLOSE('TempFILE')
  124.     
  125.     localdirectory = MYPRF.LOCALDIR'/'mkdir'/'
  126.     address 'GOFETCH'
  127.     ADDPROFILE MYPRF.HOST MYPRF.PORT MYPRF.USERNAME MYPRF.PASSWORD directory DLfilename localdirectory
  128.  
  129. END
  130. CLOSE('Batchfile')
  131.  
  132. /* Close our MessagePort */
  133. CALL CLOSEPORT "AMFTP-RESULT.1"
  134.